package com.yksj.healthtalk.ui.home;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import com.yksj.healthtalk.ui.R;
import com.yksj.healthtalk.utils.ToastUtil;

/**
 * 分组编辑
 * @author crj
 *
 */
public class GroupEditDialog extends Dialog implements android.view.View.OnClickListener{

	private int position;
	private OnDismissCallListener onDismissCallListener;
	private EditText editText;
	private Button okButton;
	private Button cancelButton;
	
	public GroupEditDialog(Context context, int theme,int position) {
		super(context, theme);
		this.position = position;
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		setContentView(R.layout.dialog_layout);
		editText = (EditText) findViewById(R.id.dialogInputText);
		okButton = (Button) findViewById(R.id.buttonOk);
		cancelButton = (Button) findViewById(R.id.buttonCancel);
		okButton.setOnClickListener(this);
		cancelButton.setOnClickListener(this);
	}
	
	public void setListener(OnDismissCallListener listener) {
		this.onDismissCallListener = listener;
	}
	
	public interface OnDismissCallListener {
		public void onDismissCall(int position,String content);
	}

	@Override
	public void onClick(View v) {
		switch(v.getId()) {
		case R.id.buttonOk:
			String str = editText.getText().toString();
			if(str.indexOf(",")>-1||str.isEmpty()) {
				ToastUtil.showLong(getContext(), "分组名称内不能有\" , \" 符号且不能为空！");
			} else {
				if(onDismissCallListener!=null) {
					onDismissCallListener.onDismissCall(position, str);
					this.dismiss();
				}
			}
			break;
		case R.id.buttonCancel:
			this.dismiss();
			break;
		}
	}
}
